<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Catch\Base\CatchModel as Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @property $id
 * @property $fid
 * @property $fbillno
 * @property $fprdorgid
 * @property $fmaterialid
 * @property $fmaterialname
 * @property $fmaterialmodel
 * @property $fmodel
 * @property $funitid
 * @property $fqty
 * @property $fbomid
 * @property $fmotype
 * @property $fmobillno
 * @property $fmoentryseq
 * @property $fmoentrystatus
 * @property $fdocumentstatus
 * @property $fplannedstarttime
 * @property $fplannedcompletiontime
 * @property $fline
 * @property $freceiptquantity
 * @property $flatestreceiptdate
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class ProductionOrder extends Model
{


    protected $table = 'production_order';

    protected $fillable = [ 'id', 'fid','back_status', 'fbillno','flow_code','flow_name','fownertypeidsety','fowneridsety_number','fowneridsety_name','fprdorgid_number','fprdorgid_name','fworkshopid_number','fworkshopid_name','fmaterialid', 'fmaterialname', 'fmaterialmodel', 'fmodel', 'funitid_number','funitid_name','funitid', 'fqty','report_qty', 'fbomid', 'fmotype', 'fmobillno', 'fmoentryseq','fpurorderno','fpurorderentryseq', 'fmoentrystatus', 'fdocumentstatus', 'fplannedstarttime', 'fplannedcompletiontime', 'fline','stock_who','creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','fid','back_status','fbillno','flow_code','flow_name','fownertypeidsety','fowneridsety_number','fowneridsety_name','fprdorgid_number','fprdorgid_name','fworkshopid_number','fworkshopid_name','fmaterialid','fmaterialname','fmaterialmodel','fmodel', 'funitid_number','funitid_name','funitid','fqty','report_qty','fbomid','fmotype','fmobillno','fmoentryseq','fpurorderno','fpurorderentryseq','fmoentrystatus','fdocumentstatus','fplannedstarttime','fplannedcompletiontime','fline','stock_who'];

    /**
     * @var array
     */
    protected array $form = ['id','fid','back_status','fbillno','flow_code','flow_name','fownertypeidsety','fowneridsety_number','fowneridsety_name','fprdorgid_number','fprdorgid_name','fworkshopid_number','fworkshopid_name','fmaterialid','fmaterialname','fmaterialmodel','fmodel', 'funitid_number','funitid_name','funitid','fqty','report_qty','fbomid','fmotype','fmobillno','fmoentryseq','fpurorderno','fpurorderentryseq','fmoentrystatus','fdocumentstatus','fplannedstarttime','fplannedcompletiontime','fline','stock_who','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'fbillno' => 'like',
        'fprdorgid' => 'like',
        'fmaterialid' => 'like',
        'fmaterialname' => 'like',
        'fmobillno' => 'like',
        'stock_who' => '=',
        'back_status' => '<>',
    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 返回订单明细
     * @return HasMany
     */
    public function details():HasMany
    {
        return $this->hasMany(ProductionOrderDetail::class,'production_order_id');
    }

    /**
     * 返回任务指派人员
     * @return HasMany
     */
    public function stockUser():HasMany
    {
        return $this->hasMany(ProductionOrderStockUser::class,'production_order_id');
    }

    /**
     * 返回工序工艺
     * @return HasMany
     */
    public function process():HasMany
    {
        return $this->hasMany(ProductionProcess::class,'production_order_id');
    }


}
